#!/usr/bin/env python
# -*- coding:utf-8 -*-
__author__ = 'walkingsky tangxn_1@163.com' 

import configparser
#import os.path
#import os

class Config:

    def __init__(self):       
        #if not os.path.exists('./default.cfg'):
        #    open('./default.cfg', 'a').close()
        pass        

    def read_ini(self,key,default_value):
        cfg_file = './default.cfg'
        config = configparser.ConfigParser()
        config.read(cfg_file)
        if len(config.sections()) == 0 :
            config.add_section('default')
            
        config_default = config['default']

        if config_default.get(key) is None:
            self.write_ini(key,default_value)
            return default_value
        else:
            return config_default.get(key)

    def write_ini(self,key,value):
        cfg_file = './default.cfg'
        config = configparser.ConfigParser()
        config.read(cfg_file)
        #print(config.sections())
        if len(config.sections()) == 0:
            config.add_section('default')
        config_default = config['default']
        config_default[key] = value
        with open(cfg_file,'w') as inifile:
            config.write(inifile)


    def get_case_path(self):
        case_path = self.read_ini('case_path','F:\\study\\test\\python_houban_test\\test_case')
        #print(case_path)
        return case_path

    def get_log_path(self):
        return self.read_ini('log_path','F:\\study\\test\\python_houban_test\\log')

    def get_test_env(self):
        return self.read_ini('test_env','product')

    def set_case_path(self,case_path):
        self.write_ini('case_path',case_path)

    def set_log_path(self,log_path):
        self.write_ini('log_path',log_path)

    def set_test_env(self,test_env):
        self.write_ini('test_env',test_env)

    
        
    


